from tensorflow import keras
import numpy as np
import pprint

(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data(r'E:\testDir\ml\mnist\mnist.npz')
print(x_train.shape,x_test.shape)
# 做归一化
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
print(scaler.__dict__)
x_train_result = scaler.fit_transform(x_train.astype(np.float32).reshape(-1,1)).reshape(-1,28,28,1)
print(scaler.__dict__)
x_valid_result = scaler.transform(x_test.astype(np.float32).reshape(-1,1)).reshape(-1,28,28,1)
print(scaler.__dict__)
print(scaler.__dict__)

scaler2 = StandardScaler()
scaler2.__setattr__("n_features_in_",1)
scaler2.__setattr__("n_samples_seen_",47040000)
scaler2.__setattr__("mean_",np.array([33.31842145]))
scaler2.__setattr__("var_",np.array([6172.85049713]))
scaler2.__setattr__("scale_",np.array([78.56749008]))

x_valid_result2 = scaler2.transform(x_test.astype(np.float32).reshape(-1,1)).reshape(-1,28,28,1)
print(scaler2.__dict__)
